package reflect;

import java.lang.reflect.Method;
import java.util.Scanner;

public class ReflectDemo4 {
    public static void main(String[] args) throws Exception {
        Person p = new Person();
        p.sayHello();

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入类名：");
        String className = sc.nextLine();
        System.out.println("请输入方法名：");
        String methodName = sc.nextLine();

        //实例化
        Class c = Class.forName("reflect.Person");
        Object obj = c.newInstance();
        //调用方法sayHello()
        Method m = c.getMethod("sayHello");
        //调用方法
        m.invoke(obj);
    }
}
